package main

import (
	"html/template"

	"net/http"
	c "testcmd/controllers"
	r "testcmd/route"
)

type Todo struct {
	Task string
	Done bool
}

func sayhelloName(w http.ResponseWriter, r *http.Request) {
	todos := []Todo{
		{"Learn Go", true},
		{"Read Go Web Examples", true},
		{"Create a web app in Go", false},
	}
	tmpl, _ := template.ParseFiles("views/404.html")
	tmpl.Execute(w, struct{ Todos []Todo }{todos})
}
func htmlAdd(w http.ResponseWriter, r *http.Request) {
	tmpl, _ := template.ParseFiles("views/addgood.html")
	tmpl.Execute(w, "")
}

func main() {
	//1.静态资源文件2.请求
	mux := r.New("views", sayhelloName)
	//1.请求方式2.请求路径3.请求
	mux.AddRoute("get", "/login_", c.HtmlLogin)
	mux.AddRoute("get", "/addhtml", htmlAdd)
	mux.AddRoute("post", "/login", c.Login)
	mux.AddRoute("get", "/goodsAll", c.GoodsAll)
	mux.AddRoute("get", "/delgood", c.Delgood)
	mux.AddRoute("post", "/addgood", c.Addgood)

	//设置监听接口
	mux.Listen(":9898")

}
